
import { lazy,Suspense } from 'react'
import { Navigate } from 'react-router-dom'
import { useSelector } from 'react-redux'
var Index = lazy(() => import('@/views/Index/Index.tsx'))
var Login = lazy(() => import('@/views/Login/Login.tsx'))
var NotFound = lazy(() => import('@/views/NotFound/NotFound.tsx'))
var Tt = lazy(() => import('../views/Index/Tt/Tt.tsx'))
var Home = lazy(() => import('@/views/Index/Home/Home.tsx'))
var Swiper = lazy(() => import('@/views/Index/Swiper/Swiper.tsx'))
var Users = lazy(() => import('@/views/Index/Users/Users.tsx'))
var Adduser = lazy(() => import('../views/Index/Users/Adduser'))
var Addswiper = lazy(() => import('../views/Index/Swiper/Addswiper.tsx'))
var Edituser = lazy(() => import('../views/Index/Users/Edituser.tsx'))
var Shopinfo = lazy(() => import('../views/Index/Shopping/ShopInfo.tsx'))
var Seckill = lazy(() => import('../views/Index/Seckill/Seckill.tsx'))
var Recommend = lazy(() => import('../views/Index/Recommend/Recommend.tsx'))
var Sift = lazy(() => import('../views/Index/Sift/Sift.tsx'))
var Echarts = lazy(() => import('../views/Index/Echarts/Echarts.tsx'))
var Map = lazy(() => import('../views/Index/Map/Map.tsx'))
var Order = lazy(()=>import('../views/Index/Order/Order.tsx'))

// 封装一个函数式组件
// function AuthComponent({ children,permission }){
//     // 获取当前用户权限列表
//     var permission = useSelector(state=>state.userinfo.userinfo) ?
//     JSON.parse(permission[0]).checkedKeys : []
//     var res = permission && permission.includes(checkedKeys)
//     return (
//         <Suspense>
//             {
//               //如果res为true,则表示有权限访问,渲染children对应的组件
//                 //如果res为false,则表示没有权限访问,渲染NotFound组件
//                 res ?
//                 children :
//                 <NotFound/>  
//             }
//         </Suspense>
//     )
// }

export default [
    {
        path: '/index',
        element: <Index />,
        children: [
            {
                path: '/index/home',
                element: <Home />,
            },
            {
                path: '/index/swiper',
                element: <Swiper />,
                auth:'0-0'
            },
            {
                path: '/index/users',
                element: <Users />,
                auth:'0-1'
            },
            {
                path: '/index/addswiper',
                element: <Addswiper />
            },
            {
                path: '/index/adduser',
                element: <Adduser />
            },
            {
                path: '/index/edituser',
                element: <Edituser />
            },
            {
                path: '/index/shopinfo',
                element: <Shopinfo />,
                auth:'0-2-0'
            },
            {
                path: '/index/seckill',
                element: <Seckill />,
                auth:'0-2-1'
            },
            {
                path: '/index/recommend',
                element: <Recommend />,
                auth:'0-2-2'
            },
            {
                path: '/index/sift',
                element: <Sift />,
                auth:'0-2-3'
            },
            {
                path: '/index/echarts',
                element: <Echarts />,
                auth:'0-3'
            },
            {
                path: '/index/map',
                element: <Map />,
                auth:'0-5'
            },
            {
                path: '/index/editor',
                element: <Tt />,
                auth:'0-4'
            },
            {
                path: '/index/order',
                element: <Order/>
            },
            {
                path: '/index',
                element: <Navigate to="/index/home" />
            },
            {
                path: '*',
                element: <NotFound />
            }
        ]
    },
    {
        path: '/login',
        element: <Login />
    },
    {
        path: '/',
        element: <Navigate to="/index" />
    },
    {
        path: '*',
        element: <NotFound />
    },
]